//HLSL
Shader "Pao/DepthStencilMask_URP"
{
    Properties
    {
        _Color("Color", Color) = (1,1,1,1)

        _Stencil ("Stencil ID", Float) = 0              
        _StencilComp ("Stencil Comparison", Float) = 8  // 1:Never、2:Less、3:Equal、4:LEqual、5:Greater、6:NotEqual、7:GEqual、8:Always
        _StencilOp ("Stencil Operation", Float) = 0     // 0:Keep、1:Zero、2:Replace、3:IncrSat、4:DecrSat、5:Invert、6:IncrWrap、7:DecrWrap
        _StencilWriteMask ("Stencil Write Mask", Float) = 255
        _StencilReadMask ("Stencil Read Mask", Float) = 255
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Geometry" }

        Pass
        {
            Name "Depth-Stencil-Mask"

            Cull Back
            ZWrite On
            ZTest LEqual
            Blend SrcAlpha OneMinusSrcAlpha
            Stencil
            {
                Ref [_Stencil]
                Comp [_StencilComp]
                Pass [_StencilOp]
                ReadMask [_StencilReadMask]
                WriteMask [_StencilWriteMask]
            }

            HLSLPROGRAM

            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            CBUFFER_START(UnityPerMaterial)
            uniform half4 _Color;
            CBUFFER_END

            struct Attributes
            {
                float4 positionOS : POSITION;
            };

            struct Varyings
            {
                float4 positionHCS : SV_POSITION;
            };

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                OUT.positionHCS = TransformObjectToHClip(IN.positionOS);
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                return _Color;
            }

            ENDHLSL
        }
    }
}